package com.cl.mycontroller.controller;

import com.cl.annotation.ClComponent;
import com.cl.annotation.ClController;
import com.cl.annotation.ClRequestParam;
import com.cl.component.Cat;
import com.cl.component.Dog;
import com.cl.component.Person;

/*
* Controller层
* */
@ClController("/testController")
public class MyTestController {

//    public static void main(String[] args) {
//        Cat cat = new Cat();
//        Person person = new Person();
//        person.setCat(cat);
//
//        Cat cat1 = person.getCat();
//
//        person.getCat().setAge(0);
//
//        System.out.println(cat1.getAge());
//    }

    /*
    * 注入 Cat
    * */
    @ClComponent("Cat")
    private Cat cat;

    /*
    * 注入 Dog
    * */
    @ClComponent("Dog")
    private Dog dog;

    @ClController("/testMethod")
    public Cat test(@ClRequestParam("age") String age,@ClComponent("Cat")Cat cat){
        System.out.println("DispatcherServlet 分发");
        System.out.println(cat.getAge());
        System.out.println(dog.getCat().getAge());
        return cat;
    }

    @ClController("/testMethod02")
    public String test02(@ClRequestParam("age") String[] age){
        for (String s : age) {
            System.out.println(s);
        }
        return "hello";
    }

    @ClController("/testMethod03")
    public String test02(@ClRequestParam("age") String age){
        return age;
    }
}
